package com.jtest.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(){
        return Result.<T>builder()
                .code(200)
                .msg("ok")
                .data(null).build();
    }

    public static <T> Result<T> success(T data){
        return Result.<T>builder()
                .code(200)
                .msg("ok")
                .data(data).build();
    }

    public static <T>  Result failed(T data){
        return Result.<T>builder()
                .code(500)
                .msg("failed")
                .data(data).build();
    }
}
